package com.example.todolist.database.DAO

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.todolist.database.model.CategoryEntity
import com.example.todolist.entity.CategoryDetail

@Dao
interface CategoryDao {
    @Insert
    fun insert(categoryEntity: CategoryEntity)

    @Update
    fun update(categoryEntity: CategoryEntity)

    @Delete
    fun delete(vararg categoryEntity: CategoryEntity)

    @Query("select * from category")
    fun query(): List<CategoryEntity>

    @Query(
        "select count(todo.id) as categoryCnt,c.category_id ,c.label  " +
                "from category c left join todo on c.category_id=todo.category_id group by c.category_id"
    )
    fun queryDetail(): List<CategoryDetail>

    @Query("select count(*) from todo")
    fun getAllToDoCnt(): Int

    @Query("select count(*) from todo where todo.category_id=-1")
    fun getUnCateTodoCnt(): Int

    @Query("select * from category where category_id=-1")
    fun getUnCategory(): CategoryEntity
}